/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui.dataimportwiz;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;

import who.tmap.bo.Attrs;
import who.tmap.ui.util.DataUIHelper;
/**
 * @author stl
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class JFrameFinishWizard extends JInternalFrame {

	private Attrs table;    
	private boolean invokedByTMapWizard =false;
    
	private javax.swing.JPanel jContentPane = null;

	private javax.swing.JButton jButtonSave = null;
	private javax.swing.JPanel jPanelMap = null;
	private JLabel jLabel = null;
	private boolean updateButtonClicked =false;
	
	/**
	 * This is the default constructor
	 */
	public JFrameFinishWizard() {
		super("Data Import Wizard - Finish");
		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
	}
	
	/**
	 * Assign table information
	 * @param table
	 */
	public void setTable( Attrs table ) {
	    this.table =table;
	}
	
    /**
     * Specify if the attr import wizard been called by the TMap wizard
     * This method is called by the internalFrameActivated event of the
     * internal frame container (JDialogAttrImportWizard)
     * @param invokedByTMapWizard The invokedByTMapWizard to set.
     */
    public void setInvokedByTMapWizard(boolean invokedByTMapWizard) {
        this.invokedByTMapWizard = invokedByTMapWizard;
        updateButtonClicked =false;
        
		if ( invokedByTMapWizard ) {
		    jButtonSave.setText("Update data...");
		} else {
		    jButtonSave.setText("Save data...");			    
		}        
		
		if ( invokedByTMapWizard ) {
		    jLabel.setText( "Press the update button to use the imported data" );
		} else {
		    jLabel.setText("Press the button to save the imported data");
		}		
    }		
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new javax.swing.JPanel();
			jContentPane.setLayout(new java.awt.BorderLayout());
			jContentPane.add(getJPanelMap(), java.awt.BorderLayout.NORTH);
		}
		return jContentPane;
	}
	/**
	 * This method initializes jButtonSave
	 * 
	 * @return javax.swing.JButton
	 */
	private javax.swing.JButton getJButtonSave() {
		if(jButtonSave == null) {
			jButtonSave = new javax.swing.JButton();

			jButtonSave.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    if ( invokedByTMapWizard ) {
				        updateButtonClicked =true;
				    } else {
				        new DataUIHelper().saveAttributesAs( jContentPane, table );
				    }
				}
				
			});
		}
		return jButtonSave;
	}
	/**
	 * This method initializes jPanelMap
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJPanelMap() {
		if(jPanelMap == null) {
			jLabel = new JLabel();
			jPanelMap = new javax.swing.JPanel();

			jPanelMap.add(jLabel, null);
			jPanelMap.add(getJButtonSave(), null);
		}
		return jPanelMap;
	}

    /**
     * @return Returns the updateButtonClicked.
     */
    public boolean isUpdateButtonClicked() {
        return updateButtonClicked;
    }
    
    public void setUpdateButtonClicked( boolean updateButtonClicked ) {
    	this.updateButtonClicked =updateButtonClicked;
    }
}
